package com.tencent.iov.cowin.befsale.clue.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * controller输入输出日志
 *
 * @author Jason.wang
 * @version 1.0
 */
@Aspect
@Component
@Slf4j
public class LogAspect {

    @Around("execution(* com.tencent.iov.cowin.befsale.clue..controller..*.*(..))")
    public Object logElapseTime(ProceedingJoinPoint pjp) throws Throwable {
        Object target = pjp.getTarget();
        String methodName = pjp.getSignature().getName();
        Object[] args = pjp.getArgs();
        log.info("{}.{}() request:{}", target, methodName, args);
        long start = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        log.info("{}.{}() response:{} elapse time:{}", target, methodName, result, (end - start));
        return result;
    }
}